%% Some random number basics

%% The uniform distribution
% Generate an array of random numbers drawn from uniform distribution

a=rand(10000,1);

% Let's look at the distribution using a histogram
figure
hist(a,100)
xlabel('X')
ylabel('Counts')

%% The normal (Gaussian) distribution


%Note 'randn' not 'rand'
b=randn(1000000,1); 

figure
hist(b,100)
xlabel('X')
ylabel('Counts')

%% Creating functions with random minimums

a=rand()
f = @(x) (x-a).^2;      %this has a minimum at 'a'

x=(0:.01:1)
figure
plot(x,f(x))
xlabel('x')
ylabel('f(x)')


%% Testing our Min finder

%Our simple minimum finder we thought up in class

clc
close all
clear MF
clear classes

a=rand();
f = @(x) (x-a).^2;

MF=MinFinder290();
MF.A=0;
MF.B=1;
MF.X0=.5;
MF.F=f;
MF.StepSize=.25;
MF.TolX=1e-8;

tic
MF.finder290();
toc

MF.plot290()

fprintf('Actual: %g, Found: %g\n',a,MF.X(end))










